package com.tz.hospital.controller.register;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tz.hospital.entity.hospital_class;
import com.tz.hospital.entity.hospital_doctor;
import com.tz.hospital.entity.hospital_emp;
import com.tz.hospital.service.registerService;
import com.tz.hospital.service.impl.registerServiceImpl;

/**
 * Servlet implementation class guahoController
 */
@WebServlet("/guahoController")
public class guahoController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public guahoController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		registerService rs = new registerServiceImpl();
		HttpSession session= request.getSession();
		String ysida=request.getParameter("ysid");
		int ysid=Integer.valueOf(ysida);
		String worka=request.getParameter("work");
		int work=Integer.valueOf(worka);
		Object brida=session.getAttribute("userid");
		int brid=Integer.parseInt(String.valueOf(brida));
		String date=rs.getDateOfWeek(work);
		List<hospital_doctor> ly= rs.wdoctor(ysid);
		List<hospital_emp> lb= rs.tjemp(brid);
		List<hospital_class> lk=rs.idClass(ly.get(0).getKsid());
		
		System.out.println(ysid+"****"+date+"****"+brid);
		
		
		
		if(!ly.isEmpty()&&!lb.isEmpty()) {
			request.setAttribute("ly",ly);
			request.setAttribute("lb",lb);
			request.setAttribute("lk",lk);
			request.setAttribute("work",date);
			request.setAttribute("worka",work);
			request.getRequestDispatcher("/JSP/guahaod.jsp").forward(request, response);
		}
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
